package func;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

import org.junit.Test;

/*
public interface Function<T, R> {
    R apply(T t);
}
 */
public class FunctionDemo {
	@Test
	public void test1() {
		Function<String,Integer> f = new Function<String, Integer>() {
			@Override
			public Integer apply(String t) {
				return t.length();
			}
		};
		System.out.println(f.apply("hello"));
	}
	@Test
	public void test2() {
		Function<String,String> f = (t) -> t.toUpperCase();
		System.out.println(f.apply("world"));
	}
	@Test
	public void test3() {
		List<String> list = Arrays.asList("qwrafa","safkjowie","safksaw","afsafaf","o2r2waf");
		//  Function<String,String>            
		list.stream().map((s) -> s.toUpperCase()).forEach(s -> System.out.println(s));
		//  Function<String,String> 
		list.stream().map((s) -> s.substring(0,3)).forEach(s -> System.out.println(s));
		//  Function<String,Boolean> 
		list.stream().map((s) -> s.isEmpty()).forEach(s -> System.out.println(s));
	}
}
